<template>
  <div class="app-container">
    <div v-if="cokies!='admin'">
      <h1>没有权限</h1>
    </div>
    <div v-if="cokies=='admin'">

      <el-table
        :data="list"
        border
        fit
        highlight-current-row
      >
        <el-table-column align="center" label="序号" width="55">
          <template slot-scope="scope">{{ scope.$index }}</template>
        </el-table-column>
        <el-table-column label="ID" align="center" width="66">
          <template slot-scope="scope">{{ scope.row.id }}</template>
        </el-table-column>
        <el-table-column label="用户Id" align="center">
          <template slot-scope="scope">{{ scope.row.userId }}</template>
        </el-table-column>
        <el-table-column label="用户名" align="center">
          <template slot-scope="scope">{{ scope.row.userName }}</template>
        </el-table-column>
        <el-table-column label="创建时间" align="center">
          <template slot-scope="scope">{{ scope.row.createrTime }}</template>
        </el-table-column>
        <el-table-column label="请求的类名" align="center">
          <template slot-scope="scope">{{ scope.row.classesName }}</template>
        </el-table-column>
        <el-table-column label="请求的方法名" align="center">
          <template slot-scope="scope">{{ scope.row.methodsName }}</template>
        </el-table-column>
        <el-table-column label="请求的参数" align="center">
          <template slot-scope="scope">{{ scope.row.paramses }}</template>
        </el-table-column>
        <el-table-column label="注解上的描述" align="center">
          <template slot-scope="scope">{{ scope.row.remark }}</template>
        </el-table-column>
        <el-table-column label="IP地址" align="center">
          <template slot-scope="scope">{{ scope.row.ip }}</template>
        </el-table-column>
      </el-table>
      <div style="display:flex">
        <el-pagination
          background
          layout="sizes, prev, pager, next, jumper, ->, total, slot"
          :total="total"
          @current-change="currentChange"
          @size-change="sizeChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import Cookies from 'js-cookie'

export default {
  data() {
    return {
      list: [
        {
          id: 901,
          createrTime: 'Apr 22, 2020 11:03:42 PM',
          classesName: 'com.sailorj.controller.SysUserController',
          methodsName: 'getUserList',
          paramses: '[]',
          remark: '获取用户信息列表',
          ip: '0:0:0:0:0:0:0:1'
        }
      ],
      total: 0,
      page: 1,
      size: 10,
      cokies: ''
    }
  },
  // 启动自动执行该方法
  created() {
    this.fetchData()
  },
  methods: {
    sizeChange(pageSize) {
      this.size = pageSize
      this.fetchData()
    },
    currentChange(currentPage) {
      this.page = currentPage
      this.fetchData()
    },
    async fetchData() {
      const { data: res } = await this.$axios.get(
        'log/getSysLogList?page=' + this.page + '&size=' + this.size
      )
      console.log(res)
      this.list = res.data
      this.total = res.total
      this.cokies = Cookies.get('username')
      this.$message({
        type: 'success',
        message: '查询成功!'
      })
    }
  }
}
</script>

